<?php
function V_SanphamSearchResult(&$arrayData,$arrayDataCat,$arayDataHangsx,$id_loai,$id_hang,$tensp){
	$ulr = "?".MODUL."=sanpham&".ACTION."=List&".ACTION2."=";
	
?>
<script>
function GotoPage(iPage){
	document.frm.action =document.frm.action  + "&curPg="+iPage;
	document.frm.submit()  ;
}
function CheckValue(){
	var form = document.frmSearchText ;
	if(form.tensp.value == ""){
		alert("Mời bạn nhập vào Tên của sản phẩm cần tìm kiếm");
		form.tensp.focus();
		return false;
	}	
	return true;
}
</script>
<table width="100%" height="200%" border="0" cellpadding="3"cellspacing="0" bordercolor="#FF9900" bordercolordark="white">
<form action="<?=$ulr?>SearchProductResult" method="post" name="frmSearchText" id="frmSearchText"  onSubmit="return CheckValue()">
<input type="hidden" name="modul" value="<?=CM_getParameter("modul")?>" /> 
<input type="hidden" name="action" value="<?=CM_getParameter("action")?>" /> 
<input type="hidden" name="ACTION2" value="<?=CM_getParameter("ACTION2")?>" /> 
<tr>
<td width="324"></td>
</tr>
<tr>
<td align="left" valign="top" background="" class="left-menu-aki">
<table width="97%" border="1" align="center" cellpadding="3"cellspacing="0" bordercolor="#FF9900" bordercolordark="white">
	<tr class=bk12-140 bgcolor="#FFE59F">
	  <td colspan="3" align="left" ><div align="center"><strong>Tìm Kiếm Sản phẩm</strong></div></td>
  </tr>
	<tr>
	  <td width="231" align="left" bgcolor="#FFE59F" class=bk12-140 ><font color="#000066">Tên sản phẩm</font></td>
	  <td width="936" colspan="2" align="left"><input name="tensp" type="text" class="form200" value="<?=$tensp?>" style="WIDTH: 195px" /></td>
	</tr>
	<tr>
	  <td align="left" bgcolor="#FFE59F" class=bk12-140 ><font color="#000066">Loại sản phẩm</font> </td>
	  <td colspan="2" align="left">
		<select name="id_loai_sp" style="WIDTH: 200px">
			<option value="0"  selected>Chọn loại tất cả</option>
			<?
			if(!empty($arrayDataCat)){
				foreach($arrayDataCat as $rowCat){
					$idCat=$rowCat["id"];
					$nameCat=$rowCat["ten_loai_sp"];
					if($idCat==$id_loai){
						echo"<option value=$idCat  selected>$nameCat</option>";
					}else{
						echo"<option value=$idCat >$nameCat</option>";
					}
				}//end foreach
			}//end if
			?>
		</select>
	  </td>
  </tr>
	
	<tr>
	  <td align="left" bgcolor="#FFE59F" class=bk12-140 ><font color="#000066">Hãng sản xuất</font></td>
	  <td colspan="2" align="left">
		<SELECT name="id_hang" id="hangsx" style="WIDTH: 200px">
			<option value="0"  selected>Chọn loại tất cả</option>
			<?
			if(!empty($arayDataHangsx)){
				foreach($arayDataHangsx as $rowHangsx){
					$idHangsx=$rowHangsx["id"];
					$nameHangsx=$rowHangsx["ten_hang"];
					if($idHangsx==$id_hang){
						echo"<option value=$idHangsx  selected>$nameHangsx</option>";
					}else{
						echo"<option value=$idHangsx >$nameHangsx</option>";
					}
				}//end foreach
			}//end if
			?>
		</SELECT>
	  </td>
  </tr>
	
	<tr>
	  <td align="left">&nbsp;</td>
	  <td ><span class="bk12-140">
		  <input type="submit" name="Submit" value="     Tìm kiếm   "/>
		<input name="nhaplai" type="reset" id="re" value=" Nhập lại   " />
	  </span></td>
	</tr>
  </table></td>
</tr>
<tr>
<td width="324" style="height:30px; ">&nbsp;</td>
</tr>
<tr>
<td>
	<div id="searchdiv"></div>
</td>
</tr>
</form>
</table>
<div style="padding-left:20px; ">
<font size="4" color="#FF0000" >Kết quả tìm kiếm : </font> <br>
<hr width="15%" size="1" align="left">
</div>
<?

	//phan trang
	$totalRows = 0;
	$paging="";
	$totalRows=count($arrayData);
	$maxRows = MAXROW;
	$maxPages =MAXPAGES;
	if($totalRows%$maxRows==0)
		$totalPages = (int)($totalRows/$maxRows);
	else
		$totalPages = (int)($totalRows/$maxRows+1);
	$curPage =CM_getParameter("curPg");
	if($curPage=="")
		$curPage =1;
	else
		$curRow = ($curPage-1)*$maxRows+1;
	$paging ="Trang thứ :&nbsp;<font color=red>".$curPage."</font>&nbsp;&nbsp;&nbsp;"."Tổng số trang :&nbsp;<FONT color=red>".$totalPages."</FONT><br> ";
	if($totalRows>$maxRows)
	{
		$start=1;
		$end=1;
		$paging1 ="";
		for($i=1;$i<=$totalPages;$i++)
		{
			if(($i>((int)(($curPage-1)/$maxPages))* $maxPages) && ($i<=((int)(($curPage-1)/$maxPages+1))* $maxPages))
			{
				if($start==1) $start=$i;
					if($i==$curPage)
						$paging1 .=  $i."&nbsp;&nbsp;";
					else
						$paging1 .= "<a href='javascript:GotoPage(".$i.")'>".$i."</a>&nbsp;&nbsp;";
				$end=$i;
			}
		}
		$paging.= "Chọn trang :&nbsp;&nbsp;" ;
		if($curPage>$maxPages)
			$paging .="<a href='javascript:GotoPage(".($start-1).")'>Trở về</a>&nbsp;&nbsp;";
		$paging.=$paging1;
		if(((($curPage-1)/$maxPages+1)*$maxPages) < $totalPages)
			$paging .= "<a href='javascript:GotoPage(".($end+1).")'>Tiếp</a>&nbsp;&nbsp;";
	}
?>

<table width="97%" align="center">
  <tr><td>

<form name="frm" action="<?=$ulr?>SearchProductResult"  method="post" enctype="multipart/form-data" onSubmit="return CheckValue()">
<input type="hidden" name="tensp" value="<?=$tensp?>">
<input type="hidden" name="id_loai_sp" value="<?=$id_loai?>">
<input type="hidden" name="id_hang" value="<?=$id_hang?>">
<DIV style="BORDER-RIGHT: #999999 1px solid; VERTICAL-ALIGN: top; OVERFLOW: auto; BORDER-LEFT: #999999 1px solid; WIDTH: 100%px; BORDER-BOTTOM: #999999 1px solid; HEIGHT: 400px" align="center">
<TABLE width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#FF9900" bordercolordark="white">
<TBODY>
		  <TR align="center" bgcolor="#FFE59F">
			<TD width="26" height="21" align="center" valign="middle" id=th1><font size="2"><strong>STT</strong></font></TD>
			<TD width="29" align="center" valign="middle"><font size="2"><strong>Sửa</strong></font></TD>
			<TD width="29" align="center" valign="middle" id=th3><font size="2"><strong>Xóa</strong></font></TD>
			<TD width="33" align="center" valign="middle" id=th3><font size="2"><strong>Xem</strong></font></TD>
			<TD width="310" align="left" valign="middle" id=th5><font size="2"><strong>Tên sản phẩm</strong></font></TD>
			<TD width="250" align="center" valign="middle"><strong><font size="2">Hiển thị ngoài trang chủ</font></strong></TD>
			<TD width="64" align="center" valign="middle" id=th5><font size="2"><strong>album</strong></font></TD>
			<TD width="84" align="right" valign="middle" id=th5><font size="2"><strong>Thứ tự</strong></font></TD>
			<TD width="99" align="center" valign="middle" id=th4><font size="2"><strong>Trạng thái</strong></font></TD>
			<TD width="81" align="center" valign="middle" id=th4><font size="2"><strong>Hiển thị </strong></font></TD>
			<TD width="103" align="right" valign="middle" id=th7><font size="2"><strong>Ngày tạo</strong></font></TD>
			
		 </TR>
	<?
	//=======================================================================================
	if(count($arrayData)>0)
	{
		$i=0;
		$low=$curRow;
		$curRow=1;
		$stt=0;
		foreach($arrayData as $row)
		{
			$stt+=1;
			if($row['trang_thai']==0)
			  $trang_thai ="Hết hàng";
			else
			  $trang_thai = "Còn hàng";
			
			$view_o_trang_chu = $row['view_o_trang_chu'];
			if($view_o_trang_chu==1){
				$checked = "checked";
			}else{
				$checked = "";
			}  
			if(($curRow <= $totalRows) && ($curRow <= $curPage*$maxRows))
			{
				$str_hienthi = "";
				if($row["hien_thi"]==1){
					$str_hienthi = 'Có';
				} else{
					$str_hienthi = 'Không';
				}
				$curRow++;
				if($curRow>$low){
					$i+1;
	?>
	  <TR>
		
		<TD height="22" align="center" valign="middle" class=bk12-140 bgcolor="#FFE59F"><strong><? echo $stt ?></strong></TD>
		<TD align="center" valign="middle" class=bk12-140 bgcolor="#FFE59F">
			<a  href="<?=$ulr."Edit"?>&id_loai_sp=<? echo $row['id_loai_sp']?>&id=<? echo $row['id']; ?>&curPg=<?=CM_getParameter("curPg");?>" onclick="return edit('<?=$row['id']?>','<?=$row['id_loai_sp']?>');">
				<img   title=Change height=16 alt=Change hspace=2   src="../images/Edit.gif" width=16 border=0>
			</a>
		</TD>
		<TD align="center" valign="middle" class=bk12-140 bgcolor="#FFE59F">
			<A  onclick="return del('<?=$row['id']?>','<?=$row['id_loai_sp']?>');" 
				href="<?=$ulr."Delete"?>&id_loai_sp=<? echo $cat_id?>&id=<? echo $row['id']; ?>&curPg=<?=CM_getParameter("curPg");?>">
					<IMG title=Drop height=16 alt=Drop hspace=2 src="../images/Delete.gif" width=16 border=0>
			</A>
		</TD>
		<TD align="center" valign="middle" class=bk12-140 bgcolor="#FFE59F"> 
			<div align="left"><a href="<?=$ulr."View"?>&id_loai_sp=<? echo $cat_id?>&id=<? echo  $row['id']; ?>&curPg=<?=CM_getParameter("curPg");?>" onclick="return View('<?=$row['id']?>');">
			    <IMG title=View height=17 alt=View hspace=2 src="../images/xem.gif" width=21 border=0>
		    </a>
	      </div></TD>
		<TD align="center" valign="middle" class=bk12-140  > 
			<div align="left">
			    <font size="2"><? echo $row['ten_sp']; ?>
          </font></div></TD>
		  
		  <TD align="center" valign="middle" class=bk12-140  > 
		  	<a class="thanh_link" href="<?=$ulr."Edit_check"?>&id_loai_sp=<? echo $cat_id?>&id=
				<? echo  $row['id']; ?>&curPg=<?=CM_getParameter("curPg");?>&view_o_trang_chu=<? echo $row['view_o_trang_chu'];?>">
			<!-- <input  type="checkbox" name="element[]" value="<?=$row['id']?>" <?=$checked?> /> -->
			<input  type="checkbox" name="element1" value="<?=$row['id']?>" <?=$checked?> />
			</a>
		  </TD>
		  <td align="center">
		  		<a href="?modul=album_sanpham&action=List&sanpham_id=<?=$row['id']?>">

				<img src="../images/icon_album.jpeg" border="0" width="16" height="16" title="Tạo album sản phẩm">

				</a>
		  </td>
		 <TD align="right" valign="middle" class=bk12-140  > 
			
			    <font size="2"><? echo $row['thu_tu']; ?></font></TD>
		<TD align="center" valign="middle" class=bk12-140  > 
			
			    <font size="2"><?=$trang_thai?></font></TD>
		<TD align="left" valign="middle" class=bk12-140> 
			<div align="center"><font size="2"><a class="thanh_link" href="<?=$ulr."Edit_ht"?>&id_loai_sp=<? echo $cat_id?>&id=
				<? echo  $row['id']; ?>&curPg=<?=CM_getParameter("curPg");?>&hien_thi=<? echo $row['hien_thi'];?>">
			    <? echo $str_hienthi; ?>
		    </a>
          </font></div></TD>
		
		<TD align="left" valign="middle" class=bk12-140>
			<div align="right"><font size="2">
				<? $ngay_dang = substr($row['ngay_dang'],0,10);?>
			    <? echo str_replace("-","/",$ngay_dang); ?>
          </font></div></TD>
		
	  </TR>
	  
	 <?
				} // end if($curRow>$low)
			}// end if(($curRow <= $totalRows) && ($curRow <= $curPage*$maxRows))
		} // end foreach($arrayData as $row)
	} // end if($arrayData>0)
	else
	{
?>
	  <tr valign="top">
			<td colspan=11 valign=center align="center"><b><font face="Arial" color="#FF0000">Không có bản ghi nào </font></b></td>
      </tr>
      <?php
		}
	  ?>

</TBODY>
</TABLE>

</div>

<table border="0" width="99%">
				<!--DWLayoutTable-->
				
<tr>
	<td width="363" rowspan="2" align=left>
	  <div align="left"><font face="Arial" color="#0066cc">Tổng số bản ghi <b><font color="#ff0000">
		<? echo($totalRows);?></font></b></font></div>
		 <hr width="40%" size="1" align="left">		  
	</td>
	<td width="565" height="23" align=right valign="top"><?=$paging?></td>
</tr>
				
</table>
<input type=hidden name="<?=ACTION2?>" value="<?=CM_getParameter(ACTION2)?>"> 
<input type=hidden name="textfield" value="<?=CM_getParameter("textfield")?>"> 
<input type=hidden name="cat_idS" value="<?=CM_getParameter("cat_idS")?>">
<input type=hidden name="cat_id" value="<?=CM_getParameter("cat_id")?>"> 
<input type=hidden name="showsS" value="<?=CM_getParameter("showsS")?>"> 
<input type=hidden name="curPg" >
</form>
</td></tr></table>
<?
}//end funtion
?>